﻿#!/usr/bin/env python3

import socket
import sys

def main():
    '''client -'''
    print(main.__doc__)
    print("="*30)

    HOST = 'localhost'                 # Symbolic name meaning all available interfaces
    PORT = 1000              # Arbitrary non-privileged port
    saddr = (HOST, PORT)
    
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.setblocking(0)

    socks = [
    socket.socket(socket.AF_INET, socket.SOCK_STREAM),
    socket.socket(socket.AF_INET, socket.SOCK_STREAM),
    ]
    print('connection to {} port {}'.format(*saddr))

    for s in socks:
        s.connect(saddr)

    msgs = [
        'Good morning. ',
        'How are you?',
        'Bye.',
    ]

    for msg in msgs:
        data = msg.encode()

        for s in socks:
            print('{}: sending {!r}'.format(s.getsockname(), data))
            s.send(data)

        for s in socks:
            data = s.recv(1024)
            print('{}: received {!r}'.format(s.getsockname(), data))
            if not data:
                print('closing socket', s.getsockname())
                s.close()


if __name__=='__main__':
    main()
